//
//  NetStatusManger.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/21.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "NetStatusManger.h"
#import "AFNetworkReachabilityManager.h"



@implementation NetStatusManger


///******用Reachability实时监测网络状况
{
    AFNetworkReachabilityManager *afNetManger;
}


- (void)dealloc
{
    [afNetManger stopMonitoring];
    afNetManger = nil;
}
+ (instancetype)shareinstance
{
    static NetStatusManger *manger = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manger = [[NetStatusManger alloc] init];
    });
    return manger;
}




- (void)netWorkStatusWithBlock:(NetStatusBlock)statusBlock
{
    __block NetworkStatusType netStatus = NetworkStatusUnknown;
    
    afNetManger = [AFNetworkReachabilityManager sharedManager];
    [afNetManger setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                
                netStatus = NetworkStatusUnknown;
                statusBlock(netStatus);
                
            case AFNetworkReachabilityStatusNotReachable:
                netStatus = NetworkStatusNotReachable;
                statusBlock(netStatus);
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                netStatus = NetworkStatusReachableViaWiFi;
                statusBlock(netStatus);
                
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                netStatus = NetworkStatusReachableVia4G;
                statusBlock(netStatus);
                break;
            default:
                break;
        }
        
    }];
    
    [afNetManger startMonitoring];
    
}


@end
